package se.webbzon.boltzmann.game.npc;

import se.webbzon.boltzmann.game.character.CharacterActionEnum;
import se.webbzon.boltzmann.game.object.dialogue.AbstractDialogue;
import se.webbzon.boltzmann.game.object.dialogue.DialogueListener;
import se.webbzon.boltzmann.npc.AbstractNPC;
import se.webbzon.boltzmann.npc.NPCDuty;

public class TalkingDuty extends NPCDuty {
	
	// The priority of this duty
	private static final int priority = 0;
	
	// The dialogue associated with this duty
	private final AbstractDialogue dialogue;
	
	// A dialogue listener associated with this duty
	private Listener listener;

	/*============================================================
	Constructors
	============================================================*/
	
	/** Creates a new talking duty in the given world. **/
	public TalkingDuty(AbstractNPC npc, AbstractDialogue dialogue) {
		super(priority,npc);
		this.dialogue = dialogue;
	}
	
	/*============================================================
	Public Methods
	============================================================*/

	@Override public void onBegin() {
		AbstractNPC npc = getNPC();
		listener = new Listener(npc);
		dialogue.addListener(listener);
		npc.setAction(CharacterActionEnum.TALK);
	}

	@Override public void onStep() {};

	@Override public void onEnd() {};
	
	/*============================================================
	Private Classes
	============================================================*/
	
	private static final class Listener implements DialogueListener {
		
		// The non-player character associated with the duty
		private final AbstractNPC npc;
		
		/*============================================================
		Constructors
		============================================================*/
		
		public Listener(AbstractNPC npc) {
			this.npc = npc;
		}
		
		/*============================================================
		Public Methods
		============================================================*/

		@Override public void onShowInput(AbstractDialogue dialogue) {
			npc.setAction(CharacterActionEnum.STAND);
		}
		
	}

}
